var Page = function (){
    function initReadonly(){
        $("#E6,#E5,#E7").prop("readonly",true);
    }

    function e4Handle(){
        $("#E4").on("change",function (){
            initReadonly();
            switch (parseInt($(this).val())){
                case 1:
                    $("#E7").prop("readonly",false);

                    getUpdate($(this));
                    break;
                case 2:
                    $("#E6,#E5").prop("readonly",false);
                    getUpdate($(this));
                    break;
            }
        }).change();
    }

    function getUpdate($obj) {
        validate.init($obj);
        if (validate.isNotNumber($obj.val())) {
            validate.invalid();
            return;
        }
        $.ajax({
            url: basePath + "tools/sinkhole/updateParam",
            type:"post",
            dataType:"json",
            data:{
                paramName:$obj.attr("id"),
                paramValue:$obj.val()
            }
        });
        validate.valid()
    }

    var update = function() {
        $("input").on("blur",function() {
            getUpdate($(this));
        });
    };

    var buttonHandle = function() {
        $("#calE15").on("click",function() {
            Metronic.blockUI({
                boxed:true,
                message:"数据计算中..."
            });
            $.get(basePath + "tools/sinkhole/calE15",function(data) {
                $("#E15").val(data);
                Metronic.unblockUI();
            })
        });
        $("#cal").on("click",function() {
            Metronic.blockUI({
                boxed:true,
                message:"数据计算中..."
            });
            $.get(basePath + "tools/sinkhole/cal",function(data) {
                $("#E19").val(data.e19);
                $("#E21").val(data.e21);
                $("#E216").val(data.e216);
                $("#E217").val(data.e217);
                Metronic.unblockUI();
            });
        });
    };

    return {
        init:function (){
            getUpdate($("#E12"));
            getUpdate($("#E9"));
            e4Handle();
            update();
            window.onunload = function() {
                $.post(basePath + "tools/sinkhole/clean",function(){});
            };
            buttonHandle();
        }
    }

}();